;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var css_add = require("./permisionGroupAdd.css");
	var router = require("../hash/pageRouter")
	var roleId;
	
	var zTreeOnCheck = function(event, treeId, treeNode){
//		 alert(treeNode.tId + ", " + treeNode.name + "," + treeNode.checked+ "," + treeNode.id);
		if (treeNode.checked) {
			var i = treeNode.id;
			if (i == "0" || i == "1" || i == "2" || i == "3" || i == "4" || i == "5" || i == "6" || i == "7" || i == "8" || i == "9"|| i=="10"||
					i=="waitWork_1" || i=="exceptionHandle_1" || i=="financeApplicationManage_1" || i=="accountMoneyStatement_1" || i=="verifyList_1" || i=="financingApprove_1" || i=="contractUnsign_1" || i=="financeUnloan_1" || i=="financePickupExam_1"||
					i=="enterpriseManage_1" || i=="clientManage_1" || i=="distributors_1" || i=="memberGradeAduitList_1" || i=="temporaryAduitList_1" || i=="clientManageDetail_1"||
					i=="abnormalManage_1" || i=="exceptionManages_1" || i=="exceptionHandles_1" || i=="insuranceManages_1" || i=="memberGradeManage_1" || i=="systemSettings_1"|| i=="productManage_1"|| 
					i=="constractManages_1"|| i=="constractLogisticsManage_1" || i=="constractSupervisionManage_1"|| i=="warningSchemeManage_1" || i=="warningInfo_1" || i=="warningHistory_1"||
					i=="warehousetPickupManage_1"|| i=="warehouseWait_1" || i=="warehousePickApplicationFirst_1"|| i=="warehousePickApplicationSecond_1") {
				checkChildren(treeNode);
			}
		} else {
			var i = treeNode.id;
			if (i == "0" || i == "1" || i == "2" || i == "3" || i == "4" || i == "5" || i == "6" || i == "7" || i == "8" || i == "9"|| i=="10"||
					i=="waitWork_1" || i=="exceptionHandle_1" || i=="financeApplicationManage_1" || i=="accountMoneyStatement_1" || i=="verifyList_1" || i=="financingApprove_1" || i=="contractUnsign_1" || i=="financeUnloan_1" || i=="financePickupExam_1"||
					i=="enterpriseManage_1" || i=="clientManage_1" || i=="distributors_1" || i=="memberGradeAduitList_1" || i=="temporaryAduitList_1" || i=="clientManageDetail_1"||
					i=="abnormalManage_1"||  i=="exceptionManages_1" || i=="exceptionHandles_1" || i=="insuranceManages_1"  || i=="memberGradeManage_1" || i=="systemSettings_1"|| i=="productManage_1" ||
					i=="constractManages_1"|| i=="constractLogisticsManage_1" || i=="constractSupervisionManage_1"|| i=="warningSchemeManage_1" || i=="warningInfo_1" || i=="warningHistory_1"||
					i=="warehousetPickupManage_1"|| i=="warehouseWait_1" || i=="warehousePickApplicationFirst_1"|| i=="warehousePickApplicationSecond_1") {
				uncheckChildren(treeNode);
			}
		}
	};

	function beforeClick(treeId, treeNode) {
		var zTree = $.fn.zTree.getZTreeObj("treeDemo");
		zTree.checkNode(treeNode, !treeNode.checked, null, true);
		return false;
	}
	
	function onCheck(e, treeId, treeNode) {
		var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
		nodes = zTree.getCheckedNodes(true),
		v = "";
		for (var i=0, l=nodes.length; i<l; i++) {
			v += nodes[i].name + ",";
		}
		if (v.length > 0 ) v = v.substring(0, v.length-1);
		var cityObj = $("#citySel");
		cityObj.attr("value", v);
	}

	function showMenu() {
		var cityObj = $("#citySel");
		var cityOffset = $("#citySel").offset();
		$("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");

		$("body").bind("mousedown", onBodyDown);
	}
	function hideMenu() {
		$("#menuContent").fadeOut("fast");
		$("body").unbind("mousedown", onBodyDown);
	}
	function onBodyDown(event) {
		if (!(event.target.id == "menuBtn" || event.target.id == "citySel" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
			hideMenu();
		}
	}
	
	var setting = {
		check: {
			enable: true,
			chkboxType: {"Y":"p", "N":""},
			checkType : "checkbox"
		},
		view: {
			dblClickExpand: false
		},
		data: {
			simpleData: {
				enable: true,
				idKey: "id",
            	pIdKey: "pId"
			}
		},
		callback: {
			beforeClick: beforeClick,
			onCheck: zTreeOnCheck
		}
	};
	
	var zNodes =[
		//导航栏
		{id:"0", pId:"", name:"导航栏", check_Child_State: 2},
		{id:"mainPage_11", pId:"0", name:"首页"},
		{id:"financingManage_11", pId:"0", name:"融资项目"},
		{id:"clientManage_11", pId:"0", name:"客户管理"},
		{id:"bulkstockManage_11", pId:"0", name:"大宗商品"},
		{id:"newsManage_11", pId:"0", name:"新闻资讯"},
		{id:"exceptionManage_11", pId:"0", name:"异常管理"},
		{id:"insuranceManage_11", pId:"0", name:"保险管理"},
		{id:"systemManage_11", pId:"0", name:"系统管理"},
		{id:"warningCenter_11", pId:"0", name:"信贷管理"},
		{id:"warehousePickupCenter_11", pId:"0", name:"销售提货"},
		
		{id:"1", pId:"", name:"首页"},
		{id:"priceWarning_1", pId:"1", name:"价格波动提醒"},
		{id:"waitWork_1", pId:"1", name:"待办事项"},
		
		{id:"financingApprove_1", pId:"waitWork_1", name:"融资审批"},
		{id:"businessAudit_1", pId:"financingApprove_1", name:"商务部审批"},
		{id:"businessManageAudit_1", pId:"financingApprove_1", name:"业务领导审核"},
		{id:"operationAudit_1", pId:"financingApprove_1", name:"业务副总"},
		{id:"riskAudit_1", pId:"financingApprove_1", name:"风控审核"},
		{id:"riskMemberAudit_1", pId:"financingApprove_1", name:"风控领导审核"},
		{id:"operationManageAudit_1", pId:"financingApprove_1", name:"副总经理审核"},
		
		{id:"contractUnsign_1", pId:"waitWork_1", name:"合同管理"},
		{id:"financeContractManage_1", pId:"contractUnsign_1", name:"融资合同"},
		{id:"financeEnterpriseContractSign_1", pId:"contractUnsign_1", name:"客户签署"},
		{id:"financeContractSubmit_1", pId:"contractUnsign_1", name:"合同提交"},
		{id:"financeContractSign_1", pId:"contractUnsign_1", name:"我方签署"},
		{id:"financeContractConfirm_1", pId:"contractUnsign_1", name:"合同确认"},
		{id:"financeCallBack_1", pId:"contractUnsign_1", name:"合同打回"},
		{id:"financeSample_1", pId:"contractUnsign_1", name:"合同范本"},
		
		{id:"noticeReceive_1", pId:"waitWork_1", name:"通知锁定"},
		{id:"financeUnsupervise_1", pId:"waitWork_1", name:"确认监管"},
		
		{id:"financeUnrelease_1", pId:"waitWork_1", name:"放款申请"},
		
		{id:"financeUnloan_1", pId:"waitWork_1", name:"放款审批"},
		{id:"loanNoticeFinancialAudit_1", pId:"financeUnloan_1", name:"放款审批-资金审核"},
		{id:"loanNoticeFinancialLeaderAudit_1", pId:"financeUnloan_1", name:"放款审批-资金领导审核"},
		{id:"loanNoticeLeader1Audit_1", pId:"financeUnloan_1", name:"放款审批-副总经理审核"},
		{id:"loanNoticeLeader2Audit_1", pId:"financeUnloan_1", name:"放款审批-总经理审核"},
		{id:"loanNoticeAudit1_1", pId:"financeUnloan_1", name:"放款审批-董事长审核"},
		
		{id:"supplementContract_1", pId:"waitWork_1", name:"增补合同"},
		{id:"financeUntransport_1", pId:"waitWork_1", name:"通知运输"},
		
		{id:"financePickupExam_1", pId:"waitWork_1", name:"提货审批"},
		{id:"pickupConsentCeoAudit_1", pId:"financePickupExam_1", name:"提货审批-商务部审核"},
		{id:"pickupConsentBusinessAudit_1", pId:"financePickupExam_1", name:"提货审批-运营审核"},
		{id:"pickupConsentRiskAudit_1", pId:"financePickupExam_1", name:"提货审批-资金审核"},
		{id:"pickupConsentRiskMemberAudit_1", pId:"financePickupExam_1", name:"提货审批-资金领导审核"},
		{id:"pickupConsentFinancialAudit_1", pId:"financePickupExam_1", name:"提货审批-风控审核"},
		{id:"pickupConsentOperationAudit_1", pId:"financePickupExam_1", name:"提货审批-风控领导审核"},
		{id:"pickupConsentAudit1_1", pId:"financePickupExam_1", name:"提货审批-副总经理审核"},
		{id:"pickupConsentFinalAudit_1", pId:"financePickupExam_1", name:"提货审批-总经理审核"},
		{id:"pickupConsentAudit2_1", pId:"financePickupExam_1", name:"提货审批-董事长审核"},
		
		{id:"financeUnreceive_1", pId:"waitWork_1", name:"收款确认"},
		{id:"financeUnreceiveBulkstock_1", pId:"waitWork_1", name:"放货通知"},
		{id:"cancelSupervise_1", pId:"waitWork_1", name:"监管解除"},
		
		{id:"exceptionHandle_1", pId:"1", name:"异常处置"},
		{id:"pickupDelay_1", pId:"exceptionHandle_1", name:"提前还款"},
		{id:"interestDelay_1", pId:"exceptionHandle_1", name:"延期计息"},
		{id:"detained_1", pId:"exceptionHandle_1", name:"扣货申请"},
		{id:"pickupRansom_1", pId:"exceptionHandle_1", name:"赎货申请"},
		{id:"badassetsHandle_1", pId:"exceptionHandle_1", name:"不良资产"},
		{id:"abnormalManage_1", pId:"exceptionHandle_1", name:"异常管理"},
		
		{id:"2", pId:"", name:"融资项目"},
		{id:"financeApplicationItem_1", pId:"2", name:"融资项目"},
		
		{id:"financeApplicationManage_1", pId:"2", name:"融资申请"},
		{id:"bailAddition_1", pId:"financeApplicationManage_1", name:"保证金追加"},
		{id:"financeBookingSpace_1", pId:"financeApplicationManage_1", name:"融资订舱"},
		{id:"replenish_1", pId:"financeApplicationManage_1", name:"补货"},
		{id:"phase_1", pId:"financeApplicationManage_1", name:"收息"},
		
		{id:"endFinanceList_1", pId:"2", name:"已完成融资"},
		{id:"recieveNoticeList_1", pId:"2", name:"装货通知"},
		{id:"transportNoticeList_1", pId:"2", name:"运输通知"},
		{id:"deliveryNoticeList_1", pId:"2", name:"放货通知"},
		{id:"loanNoticeList_1", pId:"2", name:"放款审批"},
		{id:"auditBailAddition_1", pId:"2", name:"追加保证金审核"},
		{id:"bailReturnAudit_1", pId:"2", name:"保证金退还审核"},
		{id:"commissionExtractAudit_1", pId:"2", name:"佣金提取审核"},
		{id:"replenishAudit_1", pId:"2", name:"补货审核"},
		{id:"replenishConfirm_1", pId:"2", name:"补货确认"},
		{id:"constractCallBackInfo_1", pId:"2", name:"打回记录"},
		{id:"userCardAudit_1", pId:"2", name:"授信提醒"},
		{id:"cancelApplication_1", pId:"2", name:"融资取消审核"},
		
		{id:"accountMoneyStatement_1", pId:"2", name:"应收应付管理"},
		{id:"receiptManage_1", pId:"accountMoneyStatement_1", name:"应收管理"},
		{id:"disbursementManage_1", pId:"accountMoneyStatement_1", name:"应付管理"},
		{id:"receiptConfirmManage_1", pId:"accountMoneyStatement_1", name:"应收确认"},
		
		{id:"verifyList_1", pId:"2", name:"收付款单"},
		{id:"verifyReceiptList_1", pId:"verifyList_1", name:"收款单"},
		{id:"verifyDisbursementList_1", pId:"verifyList_1", name:"付款单"},
		
		{id:"3", pId:"", name:"客户管理"},
		{id:"enterpriseManage_1", pId:"3", name:"企业用户管理"},
		{id:"clientManage_1", pId:"enterpriseManage_1", name:"企业用户管理"},
		{id:"clientManageDetail_1", pId:"clientManage_1", name:"企业用户管理-详情"},
		{id:"clientManageSave_1", pId:"clientManageDetail_1", name:"企业用户管理详情-保存信息"},
		{id:"clientManageDetailAudit1_1", pId:"clientManageDetail_1", name:"企业用户管理详情-业务经理审核"},
		{id:"clientManageDetailAudit7_1", pId:"clientManageDetail_1", name:"企业用户管理详情-业务总监审核"},
		{id:"clientManageDetailAudit8_1", pId:"clientManageDetail_1", name:"企业用户管理详情-业务副总审核"},
		{id:"clientManageDetailAudit2_1", pId:"clientManageDetail_1", name:"企业用户管理详情-风控审核"},
		{id:"clientManageDetailAudit9_1", pId:"clientManageDetail_1", name:"企业用户管理详情-风控领导审核"},
		{id:"clientManageDetailAudit10_1", pId:"clientManageDetail_1", name:"企业用户管理详情-副总经理审核"},
		{id:"clientManageDetailAudit3_1", pId:"clientManageDetail_1", name:"企业用户管理详情-总经理审核"},
		{id:"clientManageDetailAudit12_1", pId:"clientManageDetail_1", name:"企业用户管理详情-董事长审核"},
		{id:"clientManageDetailAudit4_1", pId:"clientManageDetail_1", name:"企业用户管理详情-风控复核"},
		{id:"clientManageDetailAudit5_1", pId:"clientManageDetail_1", name:"企业用户管理详情-市场部确认"},
		{id:"clientManageDetailAudit6_1", pId:"clientManageDetail_1", name:"企业用户管理详情-计财部确认"},
		{id:"clientManageDetailAudit11_1", pId:"clientManageDetail_1", name:"企业用户管理详情-运营部确认"},
		{id:"authenticationManage_1", pId:"clientManageDetail_1", name:"实名认证管理"},
		
		{id:"clientManageDelete_1", pId:"clientManage_1", name:"企业用户管理-删除"},
		{id:"clientManageForbid_1", pId:"clientManage_1", name:"企业用户管理-禁用"},
		{id:"clientManageFreeze_1", pId:"clientManage_1", name:"企业用户管理-冻结"},
		{id:"clientManageReuse_1", pId:"clientManage_1", name:"企业用户管理-启用"},
		
		{id:"memberGradeAduitList_1", pId:"enterpriseManage_1", name:"用户等级审核"},
		{id:"enterpriseManageAudit1_1", pId:"memberGradeAduitList_1", name:"用户等级审核-业务经理审核"},
		{id:"enterpriseManageAudit7_1", pId:"memberGradeAduitList_1", name:"用户等级审核-业务总监审核"},
		{id:"enterpriseManageAudit8_1", pId:"memberGradeAduitList_1", name:"用户等级审核-业务副总审核"},
		{id:"enterpriseManageAudit2_1", pId:"memberGradeAduitList_1", name:"用户等级审核-风控审核"},
		{id:"enterpriseManageAudit9_1", pId:"memberGradeAduitList_1", name:"用户等级审核-风控领导审核"},
		{id:"enterpriseManageAudit10_1", pId:"memberGradeAduitList_1", name:"用户等级审核-副总经理审核"},
		{id:"enterpriseManageAudit3_1", pId:"memberGradeAduitList_1", name:"用户等级审核-总经理审核"},
		{id:"enterpriseManageAudit12_1", pId:"memberGradeAduitList_1", name:"用户等级审核-董事长审核"},
		{id:"enterpriseManageAudit4_1", pId:"memberGradeAduitList_1", name:"用户等级审核-风控复核"},
		{id:"enterpriseManageAudit5_1", pId:"memberGradeAduitList_1", name:"用户等级审核-市场部确认"},
		{id:"enterpriseManageAudit6_1", pId:"memberGradeAduitList_1", name:"用户等级审核-计财部确认"},
		{id:"enterpriseManageAudit11_1", pId:"memberGradeAduitList_1", name:"用户等级审核-运营部确认"},
		{id:"enterpriseQualification_1", pId:"memberGradeAduitList_1", name:"用户资质审核"},
		{id:"memberGradeAdjust_1", pId:"memberGradeAduitList_1", name:"资信等级调整"},
		{id:"memberGradeAdjust_1", pId:"memberGradeAduitList_1", name:"临时额度调整"},
		
		{id:"temporaryAduitList_1", pId:"enterpriseManage_1", name:"临时额度审核"},
		{id:"temporaryAudit1_1", pId:"temporaryAduitList_1", name:"临时额度-业务经理审核"},
		{id:"temporaryAudit7_1", pId:"temporaryAduitList_1", name:"临时额度-业务总监审核"},
		{id:"temporaryAudit8_1", pId:"temporaryAduitList_1", name:"临时额度-业务副总审核"},
		{id:"temporaryAudit2_1", pId:"temporaryAduitList_1", name:"临时额度-风控审核"},
		{id:"temporaryAudit9_1", pId:"temporaryAduitList_1", name:"临时额度-风控领导审核"},
		{id:"temporaryAudit10_1", pId:"temporaryAduitList_1", name:"临时额度-副总经理审核"},
		{id:"temporaryAudit3_1", pId:"temporaryAduitList_1", name:"临时额度-总经理审核"},
		{id:"temporaryAudit4_1", pId:"temporaryAduitList_1", name:"临时额度-风控复核"},
		{id:"temporaryAudit5_1", pId:"temporaryAduitList_1", name:"临时额度-市场部确认"},
		{id:"temporaryAudit6_1", pId:"temporaryAduitList_1", name:"临时额度-计财部确认"},
		{id:"temporaryAudit11_1", pId:"temporaryAduitList_1", name:"临时额度-运营部确认"},
		
		{id:"logisticsUserManage_1", pId:"3", name:"物流公司管理"},
		{id:"distributors_1", pId:"3", name:"分销商管理"},
		{id:"distributorsDel_1", pId:"distributors_1", name:"分销商管理-删除"},
		{id:"distributorsForb_1", pId:"distributors_1", name:"分销商管理-禁用"},
		{id:"distributorsFre_1", pId:"distributors_1", name:"分销商管理-冻结"},
		{id:"distributorsEnb_1", pId:"distributors_1", name:"分销商管理-启用"},
		{id:"distributorsEarning_1", pId:"distributors_1", name:"分销商管理-佣金"},
		
		{id:"followInfo_1", pId:"3", name:"客户跟进管理"},
		
		{id:"4", pId:"", name:"大宗商品"},
		{id:"bulkstockCategoryManage_1", pId:"4", name:"商品类别管理"},
		{id:"bulkstockManage_1", pId:"4", name:"大宗商品管理"},
		{id:"bulkstockPriceCollection_1", pId:"4", name:"商品价格采集"},
		
		{id:"5", pId:"", name:"新闻资讯"},
		{id:"newsInformationManage_1", pId:"5", name:"新闻资讯管理"},
		{id:"newsBannerManage_1", pId:"5", name:"栏目管理"},
		
		{id:"6", pId:"", name:"异常管理"},
		{id:"exceptionManages_1", pId:"6", name:"异常管理"},
		{id:"exceptionUnprocess_1", pId:"exceptionManages_1", name:"未处理异常"},
		{id:"exceptionAccepted_1", pId:"exceptionManages_1", name:"已接受异常"},
		{id:"exceptionCompleted_1", pId:"exceptionManages_1", name:"处理完毕异常"},
		
		{id:"exceptionHandles_1", pId:"6", name:"异常处置"},
		{id:"pickupPreA_1", pId:"exceptionHandles_1", name:"提前还款处理"},
		{id:"pickupDelayA_1", pId:"exceptionHandles_1", name:"延期还款处理"},
		{id:"interestDelayA_1", pId:"exceptionHandles_1", name:"延期计息处理"},
		{id:"detainedA_1", pId:"exceptionHandles_1", name:"扣货申请处理"},
		{id:"pickupRansomA_1", pId:"exceptionHandles_1", name:"赎货申请处理"},
		{id:"badassetsHandleA_1", pId:"exceptionHandles_1", name:"不良资产处理"},
		
		{id:"7", pId:"", name:"保险管理"},
		{id:"insuranceManages_1", pId:"7", name:"保险管理"},
		{id:"insurance1_1", pId:"insuranceManages_1", name:"待审核"},
		{id:"insurance2_1", pId:"insuranceManages_1", name:"已生效"},
		{id:"insurance3_1", pId:"insuranceManages_1", name:"已撤销"},
		{id:"insurance4_1", pId:"insuranceManages_1", name:"已拒绝"},
		
		{id:"claimManage_1", pId:"7", name:"理赔管理"},
		
		{id:"8", pId:"", name:"系统管理"},
		{id:"orgaizationManage_1", pId:"8", name:"组织管理"},
		{id:"permisionGroupManage_1", pId:"8", name:"角色权限"},
		{id:"announceManage_1", pId:"8", name:"公告管理"},
		{id:"advertisementManage_1", pId:"8", name:"广告管理"},
		
		{id:"memberGradeManage_1", pId:"8", name:"会员等级管理"},
		{id:"memberGradeEdit_1", pId:"memberGradeManage_1", name:"会员等级编辑"},
		{id:"memberGradeView_1", pId:"memberGradeManage_1", name:"会员等级查看"},
		
		{id:"financeNormManage_1", pId:"8", name:"融资附件管理"},
		
		{id:"systemSettings_1", pId:"8", name:"系统设置"},
		{id:"systemParamManage_1", pId:"systemSettings_1", name:"系统参数管理"},
		{id:"contractTemplateManage_1", pId:"systemSettings_1", name:"合同范本管理"},
		{id:"systemParamManage_2", pId:"systemSettings_1", name:"成本类型管理"},
		
		{id:"blankInfoManager_1", pId:"8", name:"账户管理"},
		{id:"lendUintManager_1", pId:"8", name:"出借单位"},
		{id:"loansMoney_1", pId:"8", name:"融资管理"},
		
		{id:"productManage_1", pId:"8", name:"产品管理"},
		{id:"productAdd_1", pId:"productManage_1", name:"产品添加"},
		{id:"productPublished_1", pId:"productManage_1", name:"产品已发布"},
		{id:"productUnSubmit_1", pId:"productManage_1", name:"产品待提交"},
		{id:"productUnExam_1", pId:"productManage_1", name:"产品待审核"},
		{id:"productUnPublish_1", pId:"productManage_1", name:"产品待发布"},
		{id:"productStoped_1", pId:"productManage_1", name:"产品已停用"},
		
		{id:"constractManages_1", pId:"8", name:"合同管理"},
		{id:"constractLogisticsManage_1", pId:"constractManages_1", name:"物流合同"},
		{id:"logisticsConstractAdd_1", pId:"constractLogisticsManage_1", name:"物流合同添加"},
		{id:"logisticsConstractPublished_1", pId:"constractLogisticsManage_1", name:"物流合同已发布"},
		{id:"logisticsConstractUnExam_1", pId:"constractLogisticsManage_1", name:"物流合同待审核"},
		{id:"logisticsConstractUnPublish_1", pId:"constractLogisticsManage_1", name:"物流合同待发布"},
		{id:"logisticsConstractUnSubmit_1", pId:"constractLogisticsManage_1", name:"物流合同待提交"},
		{id:"logisticsConstractStoped_1", pId:"constractLogisticsManage_1", name:"物流合同已停用"},
		
		{id:"constractSupervisionManage_1", pId:"constractManages_1", name:"监管合同"},
		{id:"supervisionConstractAdd_1", pId:"constractSupervisionManage_1", name:"物流合同添加"},
		{id:"supervisionConstractPublished_1", pId:"constractSupervisionManage_1", name:"物流合同已发布"},
		{id:"supervisionConstractUnExam_1", pId:"constractSupervisionManage_1", name:"监管合同待审核"},
		{id:"supervisionConstractUnPublish_1", pId:"constractSupervisionManage_1", name:"监管合同待发布"},
		{id:"supervisionConstractUnSubmit_1", pId:"constractSupervisionManage_1", name:"监管合同待提交"},
		{id:"supervisionConstractStoped_1", pId:"constractSupervisionManage_1", name:"监管合同已停用"},
		
		{id:"capitalManager_1", pId:"8", name:"资金台账"},
		{id:"useCardTypeManager_1", pId:"8", name:"卡类管理管理"},
		{id:"useCardManager_1", pId:"8", name:"用户卡管理"},
		{id:"dataSourcer_1", pId:"8", name:"数据来源管理"},
		{id:"yirunCube_1", pId:"8", name:"一润魔方"},
		
		{id:"9", pId:"", name:"预警中心"},
		
		{id:"warningSchemeManage_1", pId:"9", name:"预警管理"},
		{id:"warningScheme_1", pId:"warningSchemeManage_1", name:"预警方案"},
		{id:"auditWarning_1", pId:"warningSchemeManage_1", name:"时效设定"},
		
		{id:"warningInfo_1", pId:"9", name:"预警信息"},
		{id:"schemeResult_1", pId:"warningInfo_1", name:"融资预警"},
		{id:"riskWarning_1", pId:"warningInfo_1", name:"合共预警"},
		
		{id:"warningHistory_1", pId:"9", name:"预警管理"},
		{id:"warningSchemeResultSettled_1", pId:"warningHistory_1", name:"融资预警"},
		{id:"riskWarningSettled_1", pId:"warningHistory_1", name:"风险预警"},
		
		{id:"10", pId:"", name:"销售提货"},
		
		{id:"warehousePickApplicationAll_1", pId:"10", name:"提货列表"},
		
		{id:"warehousetPickupManage_1", pId:"10", name:"业务申请"},
		{id:"salePickApplication_1", pId:"warehousetPickupManage_1", name:"提货"},
//		{id:"purchasePickApplication_1", pId:"warehousetPickupManage_1", name:"代采提货"},
		
		{id:"warehouseWait_1", pId:"10", name:"待办事项"},
		{id:"warehousePickApplication_1", pId:"warehouseWait_1", name:"提货申请"},
		
		{id:"warehousePickApplicationFirst_1", pId:"warehouseWait_1", name:"提货初审"},
		{id:"warehouseAudit1_1", pId:"warehousePickApplicationFirst_1", name:"商务部审核"},
		{id:"warehouseAudit2_1", pId:"warehousePickApplicationFirst_1", name:"商务部领导审核"},
		{id:"warehouseAudit3_1", pId:"warehousePickApplicationFirst_1", name:"运营审核"},
		
		{id:"warehousePickApplicationUpload_1", pId:"warehouseWait_1", name:"合同上传"},
		{id:"warehousePickApplicationSign_1", pId:"warehouseWait_1", name:"合同签署"},
		
		{id:"warehousePickApplicationSecond_1", pId:"warehouseWait_1", name:"提货政审"},
		{id:"warehouseAudit4_1", pId:"warehousePickApplicationSecond_1", name:"风控审核"},
		{id:"warehouseAudit5_1", pId:"warehousePickApplicationSecond_1", name:"风控领导审核"},
		{id:"warehouseAudit6_1", pId:"warehousePickApplicationSecond_1", name:"资金审核"},
		{id:"warehouseAudit7_1", pId:"warehousePickApplicationSecond_1", name:"资金领导审核"},
		{id:"warehouseAudit8_1", pId:"warehousePickApplicationSecond_1", name:"副总经理审核"},
		{id:"warehouseAudit9_1", pId:"warehousePickApplicationSecond_1", name:"总经理审核"},
		
		
		{id:"operateWarehousePickApplication_1", pId:"warehouseWait_1", name:"提货处理"},
	];
	
	var init = function(page) {
		$.fn.zTree.init($("#treeDemo"), setting, zNodes);
		treeObj = $.fn.zTree.getZTreeObj("treeDemo");
		treeObj.expandAll(true);
		
		if (page.params.roleId != undefined) {
			roleId = page.params.roleId;
			$(".column_title a:last").html("编辑权限组");
			$("#but_confirm").html("完成编辑");
			loadExists();
		} else {
			roleId = "";
		}
		initEvent();
	};
	
	var treeObj;

	var initEvent = function() {
		
		// 添加权限按钮
		$("#but_confirm").unbind("click").click(function(){
			if (roleId == "") {
				roleAdd();
			} else {
				roleUpdate(roleId);
			}
		});
	};
	
	// 使权限组已有的权限组getChecked
	var loadExists = function() {
		base.fnAjax({
			action : "inquireRoleDetail.json",
			oData : {
				roleId : roleId
			},
			fnSuccess : function(data) {
				var nodes = treeObj.getNodes();
				$("#permisiongroup_add_input").val(data.datas[0].roleName);
				$.each(data.datas[0].perm, function(ii, tt) {
					$.each(nodes, function() {
						getChildren(this, tt.permissionId);
					});
				});
			}
		});
	};
	
	var getChildren = function(treeNode, permissionId){
		if (treeNode.id == permissionId) {
			treeObj.checkNode(treeNode, true, true);
		}
		if (treeNode.isParent){
			for(var obj in treeNode.children){
				getChildren(treeNode.children[obj], permissionId);
			}
	    }
	};
	
	var checkChildren = function(treeNode){
		treeObj.checkNode(treeNode, true, true);
		if (treeNode.isParent){
			for(var obj in treeNode.children){
				checkChildren(treeNode.children[obj]);
			}
	    }
	};
	
	var uncheckChildren = function(treeNode){
		treeObj.checkNode(treeNode, false, false);
		if (treeNode.isParent){
			for(var obj in treeNode.children){
				uncheckChildren(treeNode.children[obj]);
			}
	    }
	};

	// 添加权限接口
	var roleAdd = function() {
		var body = {};
		body.permissionId = [];
		var ns = treeObj.getCheckedNodes(true);
		$.each(ns, function() {
			if (this.id != "" && this.id.length != 0){
				body.permissionId.push(this.id);
			}
		});
		var role_name = $("#permisiongroup_add_input").val();
		if (role_name.length == 0) {
			util.alert("权限组名称输入不能为空");
			return false;
		};
		
		if (role_name.length > 255) {
			util.alert("权限组名称长度不能超过255个字符");
			return false;
		};
		
		body.roleName = role_name;
		base.fnAjax({
			action : "createRole.json",
			async : false, // 同步异步
			nocode : false, // 是否要登陆，true为不用登陆
			oData : body,
			fnSuccess : function(data) {
				if (data.status == 200) {
					$("#but_confirm").unbind();
					router.route("permisionManage/permisionManage.html");
				}
			}
		});
	};
	
	// 修改权限接口
	var roleUpdate = function(roleId) {
		var body = {};
		body.permissionId = [];
		
		var ns = treeObj.getCheckedNodes(true);
		$.each(ns, function() {
			if (this.id != "" && this.id.length != 0){
				body.permissionId.push(this.id);
			}
		});
		
		var role_name = $("#permisiongroup_add_input").val();
		if (role_name.length == 0) {
			util.alert("权限组名称输入不能为空");
			return false;
		}
		;
		if (role_name.length > 255) {
			util.alert("权限组名称长度不能超过255个字符");
			return false;
		}
		;
		body.roleName = role_name;
		body.roleId = roleId;
		base.fnAjax({
			action : "updateRole.json",
			async : false, // 同步异步
			nocode : false, // 是否要登陆，true为不用登陆
			oData : body,
			fnSuccess : function(data) {
				if (data.status == 200) {
					$("#but_confirm").unbind();
					router.route("permisionManage/permisionManage.html");
				}
			}
		});
	};

	return {
		init : init
	};
});